package com.itheima.d3_annotation;

import org.junit.Test;

import java.lang.reflect.Method;

/*
    目标：掌握注解的解析。

    AnnotatedElement接口提供了解析注解的方法
        public Annotation[] getDeclaredAnnotations()	获取当前对象上面的注解。
        public T getDeclaredAnnotation(Class<T> annotationClass)	获取指定的注解对象
        public boolean isAnnotationPresent(Class<Annotation> annotationClass)	判断当前对象上是否存在某个注解
 */
public class AnnotationTest3 {
    @Test
    public void parseClass(){
        Class clazz= AnnotationTest2.class;
        boolean malu1 = clazz.isAnnotationPresent(MaLu1.class);
        System.out.println(malu1+"wqwqqwqwrqwrwq");
        if(malu1){
            MaLu1 malu11=(MaLu1) clazz.getDeclaredAnnotation(MaLu1.class);
            System.out.println(malu11.value()+malu11.name());
        }
    }

    @Test
    public void parseMethod() throws Exception {
        Class clazz= AnnotationTest2.class;
        Method declaredMethod = clazz.getDeclaredMethod("test");
        boolean annotationPresent = declaredMethod.isAnnotationPresent(MaLu1.class);
        if(annotationPresent){
            MaLu1 maLu1=declaredMethod.getDeclaredAnnotation(MaLu1.class);
            System.out.println(maLu1.value()+maLu1.name());
        }
    }

}
